package com.ly.demo.weixin.feign;

import com.ly.demo.weixin.req.GetAccessTokenByOoauth2Req;
import com.ly.demo.weixin.req.GetAccessTokenReq;
import com.ly.demo.weixin.req.Jscode2sessionReq;
import com.ly.demo.weixin.rsp.GetAccessTokenByOoauth2Rsp;
import com.ly.demo.weixin.rsp.GetAccessTokenRsp;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.cloud.openfeign.SpringQueryMap;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;

/**
 * @description: 微信小程序接口
 * @author: nieguochen
 * @date: 2024/1/15 13:50
 */
@FeignClient(name = "weixinFeign", url = "https://api.weixin.qq.com")
public interface WeixinFeign {

    /**
     * 小程序登录
     */
    @GetMapping(value = "/sns/jscode2session", consumes = MediaType.APPLICATION_JSON_VALUE)
    String jscode2session(@SpringQueryMap Jscode2sessionReq request);

    /**
     * 获取接口调用凭据
     * @param request
     * @return
     * https://developers.weixin.qq.com/doc/offiaccount/Basic_Information/Get_access_token.html
     */
    @GetMapping(value = "/cgi-bin/token", consumes = MediaType.APPLICATION_JSON_VALUE)
    GetAccessTokenRsp getAccessToken(@SpringQueryMap GetAccessTokenReq request);

    /**
     * 通过code换取网页授权access_token
     * @param request
     * @return
     * https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/Wechat_webpage_authorization.html#3
     */
    @GetMapping(value = "/sns/oauth2/access_token", consumes = MediaType.APPLICATION_JSON_VALUE)
    GetAccessTokenByOoauth2Rsp getAccessTokenByOoauth2(@SpringQueryMap GetAccessTokenByOoauth2Req request);
}
